package com.lemon.boot.controller;

import com.lemon.boot.common.base.BaseController;
import com.lemon.boot.common.utils.JwtUtil;
import com.lemon.boot.dto.UserDTO;
import com.lemon.boot.po.UserPO;
import com.lemon.boot.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.PermitAll;
import java.util.List;

/**
 * 用户表控制层
 *
 * @author 李猛
 * @since 2024-02-11
 */
@Log4j2
@Api(tags = "用户管理")
@RestController
@RequestMapping("user")
public class UserController extends BaseController<UserPO, UserDTO, IUserService> {
    /**
     * 根据部门ID查询用户
     *
     * @return
     */
    @ApiOperation(value = "根据部门ID查询用户")
    @GetMapping("getByDeptId/{deptId}")
    public List<UserPO> getByDeptId(@PathVariable("deptId") Long deptId) {
        return super.service.getByDeptId(deptId);
    }

    /**
     * 获取当前用户的个人资料
     *
     * @return
     */
    @PermitAll
    @ApiOperation(value = "获取当前用户的个人资料")
    @GetMapping("getByCurrent")
    public UserPO getByCurrent() {
        return super.service.get(JwtUtil.getCurrentUser().getUserId());
    }

    /**
     * 修改当前用户的个人资料
     *
     * @return
     */
    @PermitAll
    @ApiOperation(value = "修改当前用户的个人资料")
    @PutMapping("updateByCurrent")
    public String updateByCurrent(@RequestBody UserPO userPO) {
        return super.service.updateByCurrent(userPO);
    }
}